package com.xxdh.config;

import com.xxdh.exception.BusiException;
import com.xxdh.util.Result;
import com.xxdh.util.ResultConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 *全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class WebExceptionAdvice {

    @ExceptionHandler(BusiException.class)
    public String businessException(BusiException e) {
        log.error("捕获到业务异常:{}", e.getMessage());
        return Result.fail(e.getMessage()).toJSONString();
    }

    @ExceptionHandler(Exception.class)
    public String exception(Exception e) {
        log.error("捕获到服务器异常:{}", e.toString());
        return Result.fail(ResultConstants.SYSTEM_ERROR).toJSONString();
    }
}
